﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MVC5Test.Infrastructure
{
    public class MyCustomHttpModule : IHttpModule
    {
        public void Dispose()
        {
        }
        /// <summary>
        /// 在对应
        /// </summary>
        public event EventHandler MyCustomHttpModuleEvent;
        /// <summary>
        /// 在Init函数中初始化事件
        /// </summary>
        /// <param name="context"></param>
        public void Init(HttpApplication context)
        {
            //实现HttpApplication中的事件
            context.BeginRequest += Context_BeginRequest;
            context.EndRequest += Context_EndRequest;
        }

        private void Context_EndRequest(object sender, EventArgs e)
        {
            var context = sender as HttpApplication;
            if (context != null)
            {
                context.Response.Write("<h2 style=\"color:blue\">这个是事件：Context_EndRequest</h2>");
            }
        }

        private void Context_BeginRequest(object sender, EventArgs e)
        {
            var context = sender as HttpApplication;
            if(context != null)
            {
                context.Response.Write("这个是事件：Context_BeginRequest");
            }
        }
    }
}